package cn.com.huzo.service.tech.impl;

import cn.com.huzo.model.entities.tech.ProductBomLinesProductColourEntity;
import cn.com.huzo.repository.tech.ProductBomLinesProductColourRepository;
import cn.com.huzo.repository.tech.ProductBomLinesRepository;
import cn.com.huzo.service.tech.ProductBomLinesProductColourManager;
import huzofw.service.impl.GenericManagerImpl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * EBOM-成品色管理服务对象类实现。
 *
 * @author 吴旭
 */
@Service("ProductBomLinesProductColourManager")
public class ProductBomLinesProductColourManagerImpl extends GenericManagerImpl<ProductBomLinesProductColourEntity, String>
        implements ProductBomLinesProductColourManager {

    @Resource(name = "ProductBomLinesRepository")
    private ProductBomLinesRepository _dao_lines;

    @Resource(name = "ProductBomLinesProductColourRepository")
    private ProductBomLinesProductColourRepository _dao_lines_product_colour;

    /**
     * {@inheritDoc}
     *
     * @throws java.lang.Exception
     */
    @Override
    public List<ProductBomLinesProductColourEntity> fetchByHeaderId(Long headerId) throws Exception {
        return _dao_lines_product_colour.fetchByHeaderId(headerId);
    }

    /**
     * {@inheritDoc}
     *
     */
    @Override
    @Transactional
    public Map<String, Object> batchInsert(List<ProductBomLinesProductColourEntity> itemList) throws Exception {
        Map<String, Object> _result = new HashMap();
        // 插入新增的成品
        _dao_lines_product_colour.batchInsert(itemList);

        _result.put("Success", true);
        _result.put("LinesList", _dao_lines.fetchByHeaderId(itemList.get(0).getHeaderId()));
        _result.put("ProductColourNode", _dao_lines_product_colour.fetchByHeaderId(itemList.get(0).getHeaderId()));

        return _result;
    }

    /**
     * {@inheritDoc}
     *
     * @throws java.lang.Exception
     */
    @Override
    @Transactional
    public Map<String, Object> batchUpdate(List<ProductBomLinesProductColourEntity> itemList) throws Exception {
        Map<String, Object> _result = new HashMap();

        Integer rowsAffected = _dao_lines_product_colour.batchUpdate(itemList);
        if (rowsAffected > 0) {
            _result.put("Success", true);
            _result.put("LinesList", _dao_lines.fetchByHeaderId(itemList.get(0).getHeaderId()));
            _result.put("ProductColourNode", _dao_lines_product_colour.fetchByHeaderId(itemList.get(0).getHeaderId()));
        } else {
            _result.put("Success", false);
        }

        return _result;
    }

    /**
     * {@inheritDoc}
     *
     * @throws java.lang.Exception
     */
    @Override
    @Transactional
    public Map<String, Object> updateProductColourOrder(List<ProductBomLinesProductColourEntity> itemList) throws Exception {
        Map<String, Object> _result = new HashMap();
        Integer rowsAffected = _dao_lines_product_colour.updateProductColourOrder(itemList);

        if (rowsAffected > 0) {
            _result.put("Success", true);
            _result.put("LinesList", _dao_lines.fetchByHeaderId(itemList.get(0).getHeaderId()));
            _result.put("ProductColourNode", _dao_lines_product_colour.fetchByHeaderId(itemList.get(0).getHeaderId()));
        } else {
            _result.put("Success", false);
        }

        return _result;
    }

    /**
     * {@inheritDoc}
     *
     * @throws java.lang.Exception
     */
    @Override
    @Transactional
    public Map<String, Object> deleteLines(ProductBomLinesProductColourEntity instance) throws Exception {
        Map<String, Object> _result = new HashMap();

        Integer rowsAffected = _dao_lines_product_colour.delete(instance.getLinesId());
        if (rowsAffected > 0) {
            _result.put("LinesList", _dao_lines.fetchByHeaderId(instance.getHeaderId()));
            _result.put("ProductColourNode", _dao_lines_product_colour.fetchByHeaderId(instance.getHeaderId()));
            _result.put("Success", true);
        } else {
            _result.put("Success", false);
        }

        return _result;
    }
}
